-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir][LLVM] Add support for invariant group related intrinsics #115877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][LLVM] Add support for invariant group related intrinsics #115877
Conversation
|
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-llvm Author: Sirui Mu (Lancern) ChangesThis PR adds support for the following LLVM intrinsics:
Full diff: https://github.com/llvm/llvm-project/pull/115877.diff 5 Files Affected:
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index d07ebbacc60434..b0d6148726f61c 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -320,6 +320,24 @@ def LLVM_InvariantEndOp : LLVM_ZeroResultIntrOp<"invariant.end", [2],
"qualified(type($ptr))";
}
+def LLVM_LaunderInvariantGroupOp
+ : LLVM_OneResultIntrOp<"launder.invariant.group", [], [0],
+ [DeclareOpInterfaceMethods<PromotableOpInterface>,
+ SameOperandsAndResultType]> {
+ let arguments = (ins LLVM_AnyPointer:$ptr);
+ let results = (outs LLVM_AnyPointer:$res);
+ let assemblyFormat = "$ptr attr-dict `:` qualified(type($ptr))";
+}
+
+def LLVM_StripInvariantGroupOp
+ : LLVM_OneResultIntrOp<"strip.invariant.group", [], [0],
+ [DeclareOpInterfaceMethods<PromotableOpInterface>,
+ SameOperandsAndResultType]> {
+ let arguments = (ins LLVM_AnyPointer:$ptr);
+ let results = (outs LLVM_AnyPointer:$res);
+ let assemblyFormat = "$ptr attr-dict `:` qualified(type($ptr))";
+}
+
// Constrained Floating-Point Intrinsics.
class LLVM_ConstrainedIntr<string mnem, int numArgs,
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
index 5dc506c14ef96f..086abdc55fd235 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
@@ -590,6 +590,30 @@ DeletionKind LLVM::InvariantEndOp::removeBlockingUses(
return DeletionKind::Delete;
}
+bool LLVM::LaunderInvariantGroupOp::canUsesBeRemoved(
+ const SmallPtrSetImpl<OpOperand *> &blockingUses,
+ SmallVectorImpl<OpOperand *> &newBlockingUses,
+ const DataLayout &dataLayout) {
+ return true;
+}
+
+DeletionKind LLVM::LaunderInvariantGroupOp::removeBlockingUses(
+ const SmallPtrSetImpl<OpOperand *> &blockingUses, OpBuilder &builder) {
+ return DeletionKind::Delete;
+}
+
+bool LLVM::StripInvariantGroupOp::canUsesBeRemoved(
+ const SmallPtrSetImpl<OpOperand *> &blockingUses,
+ SmallVectorImpl<OpOperand *> &newBlockingUses,
+ const DataLayout &dataLayout) {
+ return true;
+}
+
+DeletionKind LLVM::StripInvariantGroupOp::removeBlockingUses(
+ const SmallPtrSetImpl<OpOperand *> &blockingUses, OpBuilder &builder) {
+ return DeletionKind::Delete;
+}
+
bool LLVM::DbgDeclareOp::canUsesBeRemoved(
const SmallPtrSetImpl<OpOperand *> &blockingUses,
SmallVectorImpl<OpOperand *> &newBlockingUses,
diff --git a/mlir/test/Dialect/LLVMIR/roundtrip.mlir b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
index aa558bad2299ce..f8cd23dc4e723c 100644
--- a/mlir/test/Dialect/LLVMIR/roundtrip.mlir
+++ b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
@@ -672,6 +672,16 @@ llvm.func @invariant(%p: !llvm.ptr) {
llvm.return
}
+// CHECK-LABEL: @invariant_group_intrinsics
+// CHECK-SAME: %[[P:.+]]: !llvm.ptr
+llvm.func @invariant_group_intrinsics(%p: !llvm.ptr) {
+ // CHECK: %{{.+}} = llvm.intr.launder.invariant.group %[[P]] : !llvm.ptr
+ %1 = llvm.intr.launder.invariant.group %p : !llvm.ptr
+ // CHECK: %{{.+}} = llvm.intr.strip.invariant.group %[[P]] : !llvm.ptr
+ %2 = llvm.intr.strip.invariant.group %p : !llvm.ptr
+ llvm.return
+}
+
// CHECK-LABEL: @vararg_func
llvm.func @vararg_func(%arg0: i32, ...) {
// CHECK: %[[C:.*]] = llvm.mlir.constant(1 : i32)
diff --git a/mlir/test/Target/LLVMIR/Import/intrinsic.ll b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
index 606b11175f572f..64911b09ebc85d 100644
--- a/mlir/test/Target/LLVMIR/Import/intrinsic.ll
+++ b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
@@ -802,6 +802,15 @@ define void @invariant(ptr %0) {
ret void
}
+; CHECK-LABEL: llvm.func @invariant_group
+define void @invariant_group(ptr %0) {
+ ; CHECK: %{{.+}} = llvm.intr.launder.invariant.group %{{.*}} : !llvm.ptr
+ %2 = call ptr @llvm.launder.invariant.group.p0(ptr %0)
+ ; CHECK: %{{.+}} = llvm.intr.strip.invariant.group %{{.*}} : !llvm.ptr
+ %3 = call ptr @llvm.strip.invariant.group.p0(ptr %0)
+ ret void
+}
+
; CHECK-LABEL: llvm.func @vector_insert
define void @vector_insert(<vscale x 4 x float> %0, <4 x float> %1) {
; CHECK: llvm.intr.vector.insert %{{.*}}, %{{.*}}[4] : vector<4xf32> into !llvm.vec<? x 4 x f32>
@@ -1191,6 +1200,8 @@ declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
declare ptr @llvm.invariant.start.p0(i64 immarg, ptr nocapture)
declare void @llvm.invariant.end.p0(ptr, i64 immarg, ptr nocapture)
+declare ptr @llvm.launder.invariant.group.p0(ptr nocapture)
+declare ptr @llvm.strip.invariant.group.p0(ptr nocapture)
declare void @llvm.assume(i1)
declare float @llvm.ssa.copy.f32(float returned)
diff --git a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
index cb712eb4e1262d..059abed34cd5d1 100644
--- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -1020,6 +1020,15 @@ llvm.func @invariant(%p: !llvm.ptr) {
llvm.return
}
+// CHECK-LABEL: @invariant_group
+llvm.func @invariant_group(%p: !llvm.ptr) {
+ // CHECK: call ptr @llvm.launder.invariant.group
+ %1 = llvm.intr.launder.invariant.group %p : !llvm.ptr
+ // CHECK: call ptr @llvm.strip.invariant.group
+ %2 = llvm.intr.strip.invariant.group %p : !llvm.ptr
+ llvm.return
+}
+
// CHECK-LABEL: @ssa_copy
llvm.func @ssa_copy(%arg: f32) -> f32 {
// CHECK: call float @llvm.ssa.copy
|
gysit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Looks good to me but I think we should have a test for the PromotableOpInterface. I tried to link the corresponding test case for the lifetime intrinsic below.
This patch adds support for the following LLVM intrinsics: - `llvm.launder.invariant.group` - `llvm.strip.invariant.group`
61cbd49 to
07ceb0f
Compare
Dinistro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for addressing @gysit 's comments.
gysit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks LGTM!
This PR adds support for the following LLVM intrinsics:
llvm.launder.invariant.groupllvm.strip.invariant.group